package com.beiming.moudle.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.beiming.moudle.auth.dao.BussDao;
import com.beiming.moudle.auth.entity.BussEntity;
import com.beiming.moudle.auth.entity.ProductInfoEntity;
import com.beiming.moudle.auth.entity.utillClass.BussPage;
import com.beiming.moudle.auth.entity.utillClass.ProInfoPage;
import com.beiming.moudle.auth.service.BussService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BussServiceImpl extends ServiceImpl<BussDao, BussEntity> implements BussService {

    @Autowired
    private BussDao bussDao;

    @Override
    public IPage<BussEntity> getPage(int currentPage, int pageSize, int status) {
        QueryWrapper<BussEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("bussiness_application_status",status);;
        IPage page = new Page(currentPage,pageSize);
        bussDao.selectPage(page,queryWrapper);
        return page;
    }

    @Override
    public IPage<BussEntity> getMsgPage(BussPage bussPage) {
        LambdaQueryWrapper<BussEntity> lqw = new LambdaQueryWrapper<>();
        lqw.like(Strings.isNotEmpty(bussPage.getBussinessName()),BussEntity::getBussinessName,bussPage.getBussinessName());
        lqw.like(Strings.isNotEmpty(bussPage.getBussinessCode()),BussEntity::getBussinessCode,bussPage.getBussinessCode());
        lqw.like(null!=(bussPage.getBussinessStatus()),BussEntity::getBussinessStatus,bussPage.getBussinessStatus());
        IPage pag = new Page(bussPage.getCurrentPage(),bussPage.getPageSize());
        bussDao.selectPage(pag,lqw);
        return pag;
    }
    public int updateBussStatus(BussEntity bussEntity){

        return  bussDao.updateById(bussEntity);
    }
    public int updateStopBussStatus(BussEntity bussEntity){

        return  bussDao.updateById(bussEntity);
    }

    @Override
    public String getBussUser(int id) {
        QueryWrapper<BussEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("bussiness_id",id);
        BussEntity bussEntity=  bussDao.selectOne(queryWrapper);
        return bussEntity.getBussinessName();
    }
    @Override
    public Integer getBussId(ProInfoPage proInfoPage){
        QueryWrapper<BussEntity> queryWrapper = new QueryWrapper<>();
        if (null == proInfoPage.getBussinessName()||proInfoPage.getBussinessName().equals("")){
            return 0;
        }
        queryWrapper.eq("bussiness_name",proInfoPage.getBussinessName());
        BussEntity bussEntity=getOne(queryWrapper);
        return bussEntity.getBussinessId();
    }
}



